package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AddNursingPlanDto;
import com.zzyl.dto.GetPageNursingsDto;
import com.zzyl.dto.UpdateNursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 查询全部
     * @return
     */
    @GetMapping()
    public ResponseResult getAllNursingPlan(){
       List<NursingPlanVo> nursingPlanList=nursingPlanService.getAllNursingPlan();
       return ResponseResult.success(nursingPlanList);
    }

    /**
     * 新增护理项目
     * @param dto
     * @return
     */
    @PostMapping()
    public ResponseResult addNursingPlan(@RequestBody AddNursingPlanDto dto){
        nursingPlanService.addNursingPlan(dto);
        return ResponseResult.success();
    }

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("search")
    public ResponseResult getPageNursingPlan(GetPageNursingsDto dto){
        PageResponse<NursingPlanVo> pageResponse= nursingPlanService.getPageNursingPlan(dto);
        return  ResponseResult.success(pageResponse);
    }

    /**
     * 回显
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public  ResponseResult getNursingPlanById(@PathVariable Integer id){
      NursingPlanVo nursingPlanVo = nursingPlanService.getNursingPlanById(id);
      return ResponseResult.success(nursingPlanVo);
    }

    /**
     * 修改
     * @param dto
     * @return
     */
    @PutMapping("{id}")
    public ResponseResult updateNursingPlanById(@RequestBody UpdateNursingPlanDto dto){
        nursingPlanService.updateNursingPlanById(dto);
        return ResponseResult.success("修改成功");
    }

    /**删除
     *
     */
    @DeleteMapping("{id}")
    public  ResponseResult deleteNursingPlanById(@PathVariable Integer id){
        nursingPlanService.deleteNursingPlanById(id);
        return ResponseResult.success("删除成功");
    }

    /**
     * 修改状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable("id") Integer id,@PathVariable("status") Integer status){
        nursingPlanService.updateStatus(id,status);
        return ResponseResult.success("修改状态成功");
    }
}
